<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
</head>
  <title>商务支付申请单</title>
  <style type="text/css">
  	.layui-form-select dl{
		max-height: 150px; // 原值为300，调节高度建议为50的倍数
	}
	.layui-form-label{width: 130px;}
	.layui-form-item {
	    margin-bottom: 0px;
	    clear: both;
	    *zoom: 1;
	}
  </style>
</head>
<body>
  <div class="layui-fluid">   
    <div class="layui-card">
      <!-- 查询区域  -->
      <div id="query-form" class="layui-form layui-card-header layuiadmin-card-header-auto">
       	<div class="layui-form-item">
          	<div class="layui-inline">
            	<label class="layui-form-label">单据ID</label>
            	<div class="layui-input-inline">
              		<input type="text" name="codes" placeholder="请输入单据编号" autocomplete="off" class="layui-input">
            	</div>
          	</div>
          	<div class="layui-inline">
            	<label class="layui-form-label">项目名称</label>
            	<div class="layui-input-inline">
              		<input type="text" name="proName" placeholder="请输入项目名称" autocomplete="off" class="layui-input">
            	</div>
          	</div>
          	<div class="layui-inline">
             	<label class="layui-form-label">创建日期</label>
             	<div class="layui-input-inline">
               		<input type="text" class="layui-input" id="sent-laydate-start" name="startDate" readonly placeholder="开始日期">
             	</div>
             	<div class="layui-form-mid">
               	-
             	</div>
             	<div class="layui-input-inline">
               		<input type="text" class="layui-input" id="sent-laydate-end" name="endDate" readonly placeholder="结束日期">
             	</div>
       		</div>
       	</div>
       	<div class="layui-form-item">
          	<div class="layui-inline">
            	<label class="layui-form-label">单据状态</label>
            	<div class="layui-input-inline">
              		<select name="processStatus">
		              	<option value="">请选择-单据状态</option>
		              	<option value="1">审批中</option>
		              	<option value="9">审批完成</option>
		              	<option value="10">审批终止</option>
              		</select>
            	</div>
          	</div>
          	<div class="layui-inline">
             	<label class="layui-form-label">确权月份</label>
             	<div class="layui-input-inline">
               		<input type="text" class="layui-input" id="sent-laydate-startMonth" name="monthStartDateStr" readonly placeholder="开始月份">
             	</div>
             	<div class="layui-form-mid">
               	-
             	</div>
             	<div class="layui-input-inline">
               		<input type="text" class="layui-input" id="sent-laydate-endMonth" name="monthEndDateStr" readonly placeholder="结束月份">
             	</div>
       		</div>
          	<div class="layui-inline">
            	<label class="layui-form-label">费用类型</label>
            	<div class="layui-input-inline">
              		<select name="feeType">
		              	<option value="">请选择-费用类型</option>
		              	<option value="1">总包费</option>
		              	<option value="2">分包费</option>
		              	<option value="3">设备费</option>
		              	<option value="4">代付费</option>
		              	<option value="5">前期费</option>
              		</select>
            	</div>
          	</div>
          	<div class="layui-inline">
            	<label class="layui-form-label">支付类型</label>
            	<div class="layui-input-inline">
              		<select name="payType">
		              	<option value="">请选择-支付类型</option>
		              	<option value="1">预付费</option>
		              	<option value="2">月度进度款</option>
		              	<option value="3">年度进度款</option>
		              	<option value="4">竣工付费</option>
		              	<option value="5">结算工程款</option>
		              	<option value="6">质保金返还</option>
		              	<option value="7">代付费</option>
		              	<option value="8">前期费</option>
              		</select>
            	</div>
          	</div>
          	<shiro:hasPermission name="LIST_BIZCOST_APPLY">
          	<div class="layui-inline">
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-bizcostApply-search">
	              	<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>查询
	            </button>
	            <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-reset">
	              	<i class="layui-icon layui-icon-fonts-clear  layuiadmin-button-btn"></i>重置
	            </button>
          	</div>
          	</shiro:hasPermission>
        </div>   	
    </div>       
  	  <!-- 按钮区域  -->
      <div class="layui-card-body">
      	<div style="padding-bottom: 10px;">
          	<shiro:hasPermission name="ADD_BIZCOST_APPLY">
          		<button class="layui-btn layuiadmin-btn-admin " data-type="add">
          	 		<i class="layui-icon layui-icon-add-1 layuiadmin-button-btn"></i>新建
          		</button>
          	</shiro:hasPermission>
          	<shiro:hasPermission name="EXPORT_BIZCOST_APPLY">
          		<button class="layui-btn layuiadmin-btn-admin " data-type="export" onclick="exportList();">
          	 		<i class="layui-icon layui-icon-export layuiadmin-button-btn"></i>导出
          		</button>
          </shiro:hasPermission>
        </div>
        <!-- 数据表单 -->
        <div class="layui-tab layui-tab-brief" lay-filter="component-tabs-brief">
        	<ul class="layui-tab-title">
            	<li class="layui-this" lay-id="create"><B>我发起的</B></li>
                <li lay-id="wait"><B>我审批的</B></li>
            </ul>
            <div class="layui-tab-content">
            	<div class="layui-tab-item layui-show">
        			<table id="LAY-bizcostApply-create-manage" lay-filter="LAY-bizcostApply-create-manage"></table>
                </div>
                <div class="layui-tab-item">
                    <table id="LAY-bizcostApply-wait-manage" lay-filter="LAY-bizcostApply-wait-manage"></table>
                </div>
            </div>
        </div>       
      </div>
    </div>
  </div>

  <script>
  	var payTypeJSON = <infopub:dicJson groupNo="A00010073" />;
  	var feeTypeJSON = <infopub:dicJson groupNo="A00010072" />;
  	layui.config({
    	base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  	}).extend({
    	index: 'lib/index' //主入口模块
  	}).use(['index', 'table', 'set', 'transfer', 'laydate'], function(){
    	var $ = layui.$
    	,form = layui.form
    	,table = layui.table
    	,element = layui.element
    	,laydate = layui.laydate;
    	//tab重新渲染宽度
    	element.on('tab(component-tabs-brief)', function(obj){
    		$(window).resize();
    	});
    	
  	    //开始日期
  	    var insStart = laydate.render({
  	      elem: '#sent-laydate-start'
  	      ,done: function(value, date){
  	        //更新结束日期的最小日期
  	        insEnd.config.min = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	        
  	        //自动弹出结束日期的选择器
  	       insEnd.config.elem[0].focus();
  	      }
  	    });
  	    
  	    //结束日期
  	    var insEnd = laydate.render({
  	      elem: '#sent-laydate-end'
  	      ,done: function(value, date){
  	        //更新开始日期的最大日期
  	        insStart.config.max = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	      }
  	    });
  		//确权开始月份
  	    var insStartMonth = laydate.render({
  	      elem: '#sent-laydate-startMonth'
  	      ,type: 'month'
  	      ,done: function(value, date){
  	        //更新结束日期的最小日期
  	        insEndMonth.config.min = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	        
  	        //自动弹出结束日期的选择器
  	       insEndMonth.config.elem[0].focus();
  	      }
  	    });
  	    
  	    //确权结束月份
  	    var insEndMonth = laydate.render({
  	      elem: '#sent-laydate-endMonth'
  	      ,type: 'month'
  	      ,done: function(value, date){
  	        //更新开始日期的最大日期
  	        insStartMonth.config.max = lay.extend({}, date, {
  	          month: date.month - 1
  	        });
  	      }
  	    });
 		// 正则校验
    	form.verify({
    		//验证汉字
    	    CHS: [
    	    	/^[\u0391-\uFFE5]+$/
    	    	,'只能输入汉字'
    	  	],
	    	//大于0的正整数
		  	intNumber:[
				/^[1-9]\d*$/
				,'请输入正确的数字'
		  	]
		});

    	// 表单
    	table.render({
      		elem: '#LAY-bizcostApply-create-manage'
      		,url: basePath + '/bizcostApply/queryDataByCondition?hrStaffApplyId=${SESSION_KEY_USER_DETAIL.hrStaffId }' //请求数据接口
      		,cols: [[
        		{type: 'checkbox', fixed: 'left'}
        		,{field: 'codes', title: '单据ID', width: 170,align:'center'}
        		,{field: 'proName', title: '项目名称', width: 280,align:'center'}
        		,{field: 'feeType', title: '费用类型', width: 100,align:'center', templet: function(d){
	    		  		return feeTypeJSON[d.feeType];
	          		}
        		}
        		,{field: 'cotName', title: '合同名称', width: 170,align:'center'}
        		,{field: 'sureMonth', title: '确权月份',width: 100, align:'center', templet: function(d){
        		  		return layui.util.toDateString(d.sureMonth,"yyyy-MM");
	          		}
	         	}
        		,{field: 'payType', title: '支付类别',width: 100, align:'center', templet: function(d){
	    		  		return payTypeJSON[d.payType];
	          		}
        		}
        		,{field: 'payTotal', title: '申请付款总额（元）', width: 170,align:'center', templet: function(d){
    				return formatCurrency(d.payTotal);
          		}}
        		,{field: 'orgName', title: '申请公司',width: 170,align:'center'}
        		,{field: 'deptName', title: '申请部门',width: 100,align:'center'}
        		,{field: 'staffName', title: '申请人',width: 100,align:'center'}
        		,{field: 'addTime', title: '创建时间', width: 170,align:'center', templet: function(d){
        		  		return layui.util.toDateString(d.addTime,"yyyy-MM-dd HH:mm:ss");
              		}
             	}
        		,{field: 'processStatus', title: '单据状态', width: 103, fixed: 'right',align:'center', templet: function(d){
        				if(d.processStatus == '1'){
        					return '审批中';
        				}else if(d.processStatus == '9'){
        					return '审批完成';
        				}else if(d.processStatus == '10'){
        					return '<span class="layui-badge layui-bg-cyan">审批终止</span>';
        				}
              		}
        		}
        		,{title: '操作', width: 230, align:'center', fixed: 'right',align:'center', templet: function(d){
      	  				var optStr ="";
      	  				<shiro:hasPermission name="VIEW_BIZCOST_APPLY">
      	  					optStr += '<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>详情</a>';
  	  	  				</shiro:hasPermission>
	  	  	  			if(d.processStatus == '10'){
		  	  	  			<shiro:hasPermission name="COPY_BIZCOST_APPLY">
		  	  	  				optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="copy"><i class="layui-icon layui-icon-release"></i>复制单据</a>';
		  	  				</shiro:hasPermission>
	  	  					optStr += '<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>';
	  	  	  			}
			  		  	return optStr;
        			}
        		}
      			]]
      		,page: true
      		,limit: 10
    	});
    	
    	// 表单
    	table.render({
      		elem: '#LAY-bizcostApply-wait-manage'
      		,url: basePath + '/bizcostApply/queryMyCheckDataByCondition' //请求数据接口
      		,cols: [[
        		{type: 'checkbox', fixed: 'left'}
        		,{field: 'codes', title: '单据ID', width: 170,align:'center'}
        		,{field: 'proName', title: '项目名称', width: 280,align:'center'}
        		,{field: 'feeType', title: '费用类型', width: 100,align:'center', templet: function(d){
	    		  		return feeTypeJSON[d.feeType];
	          		}
        		}
        		,{field: 'cotName', title: '合同名称', width: 170,align:'center'}
        		,{field: 'sureMonth', title: '确权月份',width: 100, align:'center', templet: function(d){
        		  		return layui.util.toDateString(d.sureMonth,"yyyy-MM");
	          		}
	         	}
        		,{field: 'payType', title: '支付类别',width: 100, align:'center', templet: function(d){
	    		  		return payTypeJSON[d.payType];
	          		}
        		}
        		,{field: 'payTotal', title: '申请付款总额（元）', width: 170,align:'center', templet: function(d){
    				return formatCurrency(d.payTotal);
          		}}
        		,{field: 'orgName', title: '申请公司',width: 170,align:'center'}
        		,{field: 'deptName', title: '申请部门',width: 100,align:'center'}
        		,{field: 'staffName', title: '申请人',width: 100,align:'center'}
        		,{field: 'addTime', title: '创建时间',width: 170, align:'center', templet: function(d){
	    		  		return layui.util.toDateString(d.addTime,"yyyy-MM-dd HH:mm:ss");
	          		}
	         	}
        		,{field: 'mineStatus', width: 105,title: '审批状态',fixed: 'right',align:'center',templet: function(d){
	              	  var stateStr = '';
	          		  if(d.mineStatus == '0'){
	          			  stateStr = '我已审批';
	          		  }else if(d.mineStatus == '1'){
	          			  stateStr = '<span class="layui-badge layui-bg-red">待我审批</span>';
	          		  }else if(d.mineStatus == '9'){
	          			  stateStr = '审批完成';
	          		  }else if(d.mineStatus == '10'){
	          			  stateStr = '<span class="layui-badge layui-bg-cyan">审批终止</span>';
	          		  }
	        			  return stateStr;
	               }
	        	}
        		,{title: '操作', width: 171, align:'center', fixed: 'right', templet: function(d){
      	  				var optStr ="";
      	  				<shiro:hasPermission name="VIEW_BIZCOST_APPLY">
      	  					optStr += '<a class="layui-btn layui-btn-xs" lay-event="view"><i class="layui-icon layui-icon-form"></i>详情</a>';
  	  	  				</shiro:hasPermission>
      	  				<shiro:hasPermission name="CHECK_BIZCOST_APPLY">
      	  				if(d.mineStatus == '1'){
  	  	  					optStr += '<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="toDispatch"><i class="layui-icon layui-icon-release"></i>去审批</a>';
      	  				}
  	  	  				</shiro:hasPermission>
			  		  	return optStr;
        			}
        		}
      			]]
      		,page: true
      		,limit: 10
    	});
    
    	<shiro:hasPermission name="LIST_BIZCOST_APPLY">
	    	//监听搜索
	    	form.on('submit(LAY-bizcostApply-search)', function(data){
	    		var tabId = $(".layui-tab-title .layui-this").attr("lay-id");
	    		if(tabId == 'create'){
	    			//执行重载
			      	table.reload('LAY-bizcostApply-create-manage', {page: {curr: 1},
			        	where: trimData(data)
			      	});
	    		}else{
	    			//执行重载
			      	table.reload('LAY-bizcostApply-wait-manage', {page: {curr: 1},
			        	where: trimData(data)
			      	});
	    		}
	    	});
	    	//重置清空
		    form.on('submit(LAY-user-back-reset)', function(data){
		    	reset_form('query-form');
		    	//额外处理select
				$("#query-form-state").val('');
				form.render();
		    });
    	</shiro:hasPermission>
    
    	// 监听操作列
    	table.on('tool(LAY-bizcostApply-create-manage)', function(obj){
      		var data = obj.data;
 			if(obj.event === 'view'){
	       		parent.layui.index.openTabsPage(basePath + '/bizcostApply/toDealOrDetail?id='+data.id,'商务支付申请单 > 详情');
	   		}else if(obj.event === 'copy'){//复制单据
	       		parent.layui.index.openTabsPage(basePath + '/bizcostApply/toCopy?id='+data.id,'商务支付申请单 > 复制单据');
	   		}else if(obj.event === 'del'){//删除
      			layer.confirm('确定要删除？',{icon:3, title :'提示'}, function(index){
          			$.ajax({
            			type : 'post',
    						url : basePath + '/flowProcess/logicDel',
    						data : {
    		    				"processId" :data.processId
    		    			},//数据，这里使用的是Json格式进行传输  
    						success:function(result){
    							if(result){
        							table.reload('LAY-bizcostApply-create-manage'); //数据刷新
        							layer.close(index); //关闭弹层
    							}else{
    								layer.msg('数据通信异常~',{icon: 0});
    			  				}
    						}
        			});
       			})
       		}
    	});
    	
    	// 监听操作列
    	table.on('tool(LAY-bizcostApply-wait-manage)', function(obj){
	      		var data = obj.data;
	 			if(obj.event === 'view'){
	       			parent.layui.index.openTabsPage(basePath + '/bizcostApply/toDealOrDetail?id='+data.id,'商务支付申请单 > 详情');
	   			}else if(obj.event === 'toDispatch'){
	   	    	  	parent.layui.index.openTabsPage(basePath + '/flowProcess/toDispatch?processId='+data.processId, '商务支付申请单 '+ ' > 审批');
	   	      	}
    	});
    
    // 按钮事件
    var active = {
      add: function(){
    	  parent.layui.index.openTabsPage(basePath + '/bizcostApply/add','商务支付申请单 > 新建');
      }
    }  
    // data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    
  });
	
  	//导出excel
   	function exportList() {
   		layer.msg("暂未上线，敬请期待~",{icon: 1});
		/*var $ = layui.$;
		var params = "?proCode=";
		params += $('#queryProCode').val().trim();
    	params += "&startDate=";
    	params += $('#sent-laydate-start').val().trim();
    	params += "&endDate=";
    	params += $('#sent-laydate-end').val().trim();
		params += "&customerName=";
    	params += $('#queryCustomerName').val().trim();
		params += "&mobile=";
    	params += $('#queryMobile').val().trim();
		params += "&provinceName=";
    	params += $('#queryProvinceName').val().trim();
		params += "&cityName=";
    	params += $('#queryCityName').val().trim();
		params += "&state=";
    	params += $('#queryState').val().trim();
		window.location.href = "${ctx}/preProject/exportToExcel"+params;*/
	}
  </script>
</body>
</html>

